---
category: String
created: '2020-05-30'
title: Trim the file extension from a file name
updated: '2021-10-13'
---

**JavaScript version**

```js trimExt.js
const trimExt = (fileName) => (fileName.indexOf('.') === -1 ? fileName : fileName.split('.').slice(0, -1).join('.'));
```

**TypeScript version**

```ts trimExt.ts
const trimExt = (fileName: string): string =>
    fileName.indexOf('.') === -1 ? fileName : fileName.split('.').slice(0, -1).join('.');
```

**Examples**

```js examples.js
trimExt('document'); // document
trimExt('document.pdf'); // document
trimExt('document.2020.pdf'); // document.2020
```
